//
//  AnnounNitoceView.m
//  Village
//
//  Created by 程虎 on 2017/9/7.
//  Copyright © 2017年 程虎. All rights reserved.
//

#import "AnnounNitoceView.h"

@interface AnnounNitoceView()

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *contentLab;
@end

@implementation AnnounNitoceView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.frame = CGRectMake(0, 0, SCREEN_W, SCREEN_H);
        [self set_UI];
    }
    return self;
}

- (void)set_UI
{
    UIView *views = [self creatViews];
    views.clipsToBounds = NO;
    [self addSubview:views];
    
    views.sd_layout
    .centerXEqualToView(self)
    .centerYEqualToView(self)
    .widthIs(290);
}

- (UIView *)creatViews
{
    UIView *views = [[UIView alloc] init];
    views.backgroundColor = [UIColor whiteColor];
    LRViewRadius(views, 10, 1, [UIColor clearColor]);
    
    UIImageView *imgs = [UIImageView new];
    imgs.image = [UIImage imageNamed:@"news_home"];
    
    UIButton *closeBtn = [[Tools shareInstance] creat_Button:@"" Color:nil BackColors:nil Font:0 tag:100];
    [closeBtn setImage:[UIImage imageNamed:@"close_login"] forState:UIControlStateNormal];
    [closeBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *btn = [[Tools shareInstance] creat_Button:@"查看详情" Color:[UIColor whiteColor] BackColors:KRedColors Font:18 tag:101];
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    LRViewRadius(btn, 5, 1, [UIColor clearColor]);
    
    self.titleLab = [[Tools shareInstance] creat_Label:@"积极展开“弘扬宪法精神”宣传活动" Color:K_TitlesColor Font:17 tag:-1 Alignment:1 Lines:0];
    
    self.contentLab = [[Tools shareInstance] creat_Label:@"政策发布单位·2017年8月26日" Color:[Util colorWithHexString:@"#bababa"] Font:13 tag:-1 Alignment:1 Lines:0];
    [views sd_addSubviews:@[imgs,closeBtn,self.titleLab,self.contentLab,btn]];
    
    imgs.sd_layout
    .centerXEqualToView(views)
    .centerYIs(views.top)
    .widthIs(80)
    .heightIs(80);
    
    closeBtn.sd_layout
    .rightSpaceToView(views, 12)
    .topSpaceToView(views, 12)
    .widthIs(15)
    .heightIs(15);
    
    self.titleLab.sd_layout
    .leftSpaceToView(views, 16.5)
    .topSpaceToView(imgs, 28)
    .centerXEqualToView(views)
    .rightSpaceToView(views, 16.5)
    .autoHeightRatio(0);
    
    self.contentLab.sd_layout
    .centerXEqualToView(views)
    .topSpaceToView(self.titleLab, 25)
    .leftSpaceToView(views, 30)
    .rightSpaceToView(views, 30)
    .autoHeightRatio(0);
    
    btn.sd_layout
    .topSpaceToView(self.contentLab, 40)
    .centerXEqualToView(views)
    .widthIs(135)
    .heightIs(45);
    
    [views setupAutoHeightWithBottomView:btn bottomMargin:25];
    
    return views;
}

- (void)btnClick:(UIButton *)buttons
{
    if (buttons.tag == 100) {
        [buttons.superview.superview.superview.superview removeFromSuperview];
    }
    else {
        if (self.announBlock) {
            [buttons.superview.superview.superview removeFromSuperview];
            self.announBlock(nil);
        }
    }
}
@end
